﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Sorting
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            /*
            WebBrowserProxy.SetProxy();
            InitializeComponent();

            try
            {
                string uri = Config.GetServerURL() + "/perm";
                string json = HttpHelper.GET(uri);
                ResponseRecList<string> r = JSONHelper.Deserialize<ResponseRecList<string>>(json);
                if (r.ReturnValue > 0)
                {
                    _permlist = r.RecList;
                    authMenu(this.menu.Items);
                    authToolBar(this.mainToolBar.Items);
                }
                else
                {
                    MessageBox.Show("该用户没有任何权限");
                    this.Close();
                }

            }
            catch (WebException)
            {
                MessageBox.Show("无法获取用户权限");
                this.Close();
            }
            */
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            /*
            Auth am = (Auth)((Control)sender).Tag;

            ItemCollection items = this.tabControl.Items;
            for (int i = 0; i < items.Count; i++)
            {
                TabItem item = (TabItem)items[i];
                if (item.Tag != null && item.Tag == am)
                {
                    item.IsSelected = true;
                    return;
                }
            }


            Grid grid = new Grid();

            if (am.Source.EndsWith("xaml"))
            {
                Frame frame = new Frame();

                //new System.Uri(am.Source, UriKind.Relative);
                frame.Source = new Uri(am.Source, UriKind.Relative);
                grid.Children.Add(frame);
            }
            else
            {
                WebBrowser webBrowser = new WebBrowser();
                webBrowser.Source = new Uri(Config.GetServerURL() + am.Source);
                grid.Children.Add(webBrowser);
            }

            System.Windows.Style myStyle = (System.Windows.Style)this.FindResource("MainTabItem");

            TabItem tabItem = new TabItem();
            tabItem.Header = am.Name;
            tabItem.Content = grid;
            tabItem.Tag = am;
            tabItem.Style = myStyle;
            this.tabControl.Items.Add(tabItem);

            tabItem.IsSelected = true;
            */

        }

     
        /**  去掉起始页上的关闭按钮  */
        private void tabControl_Loaded(object sender, RoutedEventArgs e)
        {
            TabControl tabControl = sender as TabControl;
            if (tabControl.Items.Count > 0)
            {
                TabItem mainTabItem = (TabItem)tabControl.Items[0];
                var closeBtn = mainTabItem.Template.FindName("Close", mainTabItem) as FrameworkElement;
                if (closeBtn != null)
                {
                    closeBtn.Visibility = Visibility.Collapsed;
                }
            }
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            //System.Environment.Exit(System.Environment.ExitCode);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
        }
    }
}
